/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package br.ufrn.dimap.projetodetalhadodesoftware.chatrmi.model.reference;

import br.ufrn.dimap.projetodetalhadodesoftware.chatrmi.model.actor.ClientModel;
import br.ufrn.dimap.projetodetalhadodesoftware.chatrmi.controller.exception.ObjectNotFoundExeption;
import br.ufrn.dimap.projetodetalhadodesoftware.chatrmi.controller.ClientControler;
import br.ufrn.dimap.projetodetalhadodesoftware.chatrmi.model.register.Register;
import java.net.MalformedURLException;
import java.rmi.Naming;
import java.rmi.NotBoundException;
import java.rmi.Remote;
import java.rmi.RemoteException;

/**
 *
 * @author Jorge
 */
public class ClientReference extends Reference {

    @Override
    public Remote getReference(int actor, String url) throws NotBoundException, MalformedURLException, RemoteException, ObjectNotFoundExeption {
       Remote remote;
        if(actor == ManagerReference.CLIENT){
            remote = (Remote) Naming.lookup(url);
        }else{
             if(next != null){
               remote =  (Remote) next.getReference(actor, url);
            }else{
                throw new ObjectNotFoundExeption();
            }
        }

       return remote;
    }

}
